<template>
  <div class="user clearfix">
    <div class="common-seach-wrap fr">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <div class="date_section">
          <div class="block mr10">
            <el-input
              v-model="formInline.orderNo"
              placeholder="搜索订单号"
            ></el-input>
          </div>
          <div class="block mr10">
            <el-input
              v-model="formInline.tradeNo"
              placeholder="支付流水号"
            ></el-input>
          </div>
          <div class="block mr10">
            <el-date-picker
              v-model="formInline.startDate"
              type="date"
              value-format="YYYY-MM-DD"
              placeholder="开始时间"
            >
            </el-date-picker>
          </div>
          <div class="block mr10">
            <el-date-picker
              v-model="formInline.endDate"
              type="date"
              value-format="YYYY-MM-DD"
              placeholder="结束时间"
            >
            </el-date-picker>
          </div>
        </div>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="onSubmit"
            >查询</el-button
          >
          <el-button @click="onExport" type="warning">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table
          size="small"
          :data="tableData"
          border
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column
            prop="orderNo"
            label="订单号"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="tradeNo"
            label="支付流水号"
            width="120"
          ></el-table-column>
          <el-table-column
            prop="totalMoney"
            label="订单金额"
            width="120"
          ></el-table-column>
          <el-table-column
            prop="couponMoney"
            label="优惠金额"
          ></el-table-column>
          <el-table-column prop="payMoney" label="实付金额"></el-table-column>
          <el-table-column
            prop="refundMoney"
            label="退款金额"
          ></el-table-column>
          <el-table-column prop="applyDesc" label="退款原因"></el-table-column>
          <el-table-column
            prop="createTime"
            label="退款时间"
            width="150"
          ></el-table-column>
          <el-table-column prop="" label="买家">
            <template #default="scope">
              <div>{{ scope.row.nickName }}</div>
              <div class="gray9">ID：({{ scope.row.userId }})</div>
            </template>
          </el-table-column>
          <el-table-column prop="operater" label="操作人"></el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import SupplierApi from "@/api/cash.js";
import qs from "qs";
import { useUserStore } from "@/store";
const { token } = useUserStore();
export default {
  components: {},
  data() {
    return {
      token,
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*门店列表数据*/
      storeList: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      formInline: {
        orderNo: "",
        tradeNo: "",
        startDate: "",
        endDate: "",
      },
      is_settled: "全部",

      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    addZero(n) {
      return n < 10 ? "0" + n : n;
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = this.formInline;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      self.loading = true;
      SupplierApi.refundRecordList(Params, true)
        .then((res) => {
          self.loading = false;
          self.tableData = res.data.records;
          self.totalDataNumber = res.data.total;
        })
        .catch((error) => {
          self.loading = false;
        });
    },
    getIssettled(val) {
      this.formInline.is_settled = val;
      console.log(this.formInline.is_settled);
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    /*打开添加*/
    addClick(row) {
      let self = this;
      let params = row.settledId;
      self.$router.push({
        path: "/cash/settled/detail",
        query: {
          settledId: params,
        },
      });
    },
    onExport() {
      const Params = {
        ...this.formInline,
        pageIndex: 1,
        pageSize: 9999999,
        tokensupplier: this.token,
      };
      let baseUrl = import.meta.env.VITE_BASIC_URL;
      if (!baseUrl) {
        baseUrl = window.location.protocol + "//" + window.location.host;
      }
      //let baseUrl = "http://127.0.0.1:8890";
      window.location.href =
        baseUrl +
        "/api/supplier/cash/cash/refundRecordExport?" +
        qs.stringify(Params);
    },
  },
};
</script>

<style>
.date_section {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 18px;
}
.demo-form-inline {
  display: flex;
  align-items: center;
}
</style>
